<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The MongoException class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongo.exceptions.html">« Exceptions</a></li>
      <li style="float: right;"><a href="class.mongoresultexception.html">MongoResultException »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="mongo.exceptions.html">Exceptions</a></li>
    <li>The MongoException class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.mongoexception" class="reference">

 <h1 class="title">The MongoException class</h1>
 

 <div class="partintro"><p class="verinfo">(PECL mongo &gt;= 1.0.0)</p>

  
  <div class="section" id="mongoexception.intro">
   <h2 class="title">Introduction</h2>
   <p class="para">
    Default Mongo exception.
   </p>

   <p class="para">
    This covers a bunch of different error conditions that may eventually be
    moved to more specific exceptions, but will always extend 
    <strong class="classname">MongoException</strong>.
   </p>

   <ul class="itemizedlist">

    <li class="listitem">
     <p class="para">
      <code class="literal">The MongoSomething object has not been correctly initialized by its constructor</code>
     </p>
     <p class="para">
      Code: 0
     </p>
     <p class="para">
      Probably your Mongo object is not connected to a database server.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">zero-length keys are not allowed, did you use $ with double quotes?</code>
     </p>
     <p class="para">
      Code: 1
     </p>
     <p class="para">
      You tried to save &quot;&quot; as a key.  You generally should not do this.  &quot;&quot; can 
      mess up subobject access and is used by MongoDB internally.  However, if 
      you really want, you can set 
      <a href="mongo.configuration.html#ini.mongo.allow-empty-keys" class="link">mongo.allow_empty_keys</a> 
      to true in your php.ini file to override this sanity check.  If you 
      override this, it is highly recommended that you set error checking to 
      strict to avoid string interpolation errors.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">&#039;.&#039; not allowed in key: &lt;key&gt;</code>
     </p>
     <p class="para">
      Code: 2
     </p>
     <p class="para">
      You attempted to write a key with &#039;.&#039; in it, which is prohibited.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">insert too large: &lt;size&gt;, max: &lt;max&gt;</code>
     </p>
     <p class="para">
      Code: 3
     </p>
     <p class="para">
      You&#039;re attempting to send too much data to the database at once: the
      database will only accept inserts up to a certain size (currently 16 MB).
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">no elements in doc</code>
     </p>
     <p class="para">
      Code: 4
     </p>
     <p class="para">
      You&#039;re attempting to save a document with no fields.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">size of BSON doc is &lt;size&gt; bytes, max &lt;max&gt;MB</code>
     </p>
     <p class="para">
      Code: 5
     </p>
     <p class="para">
      You&#039;re attempting to save a document that is larger than MongoDB can save.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">no documents given</code>
     </p>
     <p class="para">
      Code: 6
     </p>
     <p class="para">
      You&#039;re attempting to batch insert an empty array of documents.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">MongoCollection::group takes an array, object, or MongoCode key</code>
     </p>
     <p class="para">
      Code: 7
     </p>
     <p class="para">
      Wrong type parameter send to <span class="function"><a href="mongocollection.group.html" class="function">MongoCollection::group()</a></span>.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">field names must be strings</code>
     </p>
     <p class="para">
      Code: 8
     </p>
     <p class="para">
      You should format field selectors as 
      <code class="literal">array(&quot;field1&quot; =&gt; 1, &quot;field2&quot; =&gt; 1, ..., &quot;fieldN&quot; =&gt; 1)</code>.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">invalid regex</code>
     </p>
     <p class="para">
      Code: 9
     </p>
     <p class="para">
      The regex passed to <a href="class.mongoregex.html" class="classname">MongoRegex</a> is not of the 
      correct form.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">MongoDBRef::get: $ref field must be a string</code>
     </p>
     <p class="para">
      Code: 10
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">MongoDBRef::get: $db field must be a string</code>
     </p>
     <p class="para">
      Code: 11
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">non-utf8 string: &lt;str&gt;</code>
     </p>
     <p class="para">
      Code: 12
     </p>
     <p class="para">
      This error occurs if you attempt to send a non-utf8 string to the 
      database.  All strings going into the database should be UTF8. See php.ini
      options for the transition option of quieting this exception.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">mutex error: &lt;err&gt;</code>
     </p>
     <p class="para">
      Code: 13
     </p>
     <p class="para">
      The driver uses mutexes for synchronizing requests and responses in 
      multithreaded environments.  This is a fairly serious error and may not
      have a stack trace.  It&#039;s unusual and should be reported to maintainers
      with any system information and steps to reproduce that you can provide.
     </p>
    </li>

    <li class="listitem">
     <p class="para">
      <code class="literal">index name too long: &lt;len&gt;, max &lt;max&gt; characters</code>
     </p>
     <p class="para">
      Code: 14
     </p>
     <p class="para">
      Indexes with names longer than 128 characters cannot be created.  If you
      get this error, you should use 
      <span class="function"><a href="mongocollection.ensureindex.html" class="function">MongoCollection::ensureIndex()</a></span>&#039;s &quot;name&quot; option to 
      create a shorter name for your index.
     </p>
    </li>

   </ul>
  </div>
  

  <div class="section" id="mongoexception.synopsis">
   <h2 class="title">Class synopsis</h2>

   
   <div class="classsynopsis">
    <div class="ooclass"></div>

    
    <div class="classsynopsisinfo">
     <span class="ooclass">
      <strong class="classname">MongoException</strong>
     </span>
     <span class="ooclass">
      <span class="modifier">extends</span>
      <strong class="classname">Exception</strong>
     </span>
     {</div>
    
    
   }</div>
   

  </div>

 </div>

</div>
</div></div></body></html>